package com.itheima.pinda.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.pinda.DTO.entity.PdAuthMenu;
import com.itheima.pinda.service.PdAuthMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜单 前端控制器
 * </p>
 *
 * @author xsf
 * @since 2021-11-11
 */
@RestController
@RequestMapping("/authority/menu")
@CrossOrigin
public class PdAuthMenuController {

    @Autowired
    private PdAuthMenuService pdAuthMenuService;

    @GetMapping("/router")
    public List<PdAuthMenu>  queryMenuByUser(){
        //暂时返回所有路由
        List<PdAuthMenu> list = pdAuthMenuService.list();
//        Result<PdAuthMenu> result = new Result<PdAuthUser>(true,li);

        list.forEach(pdAuthMenu -> {
            QueryWrapper<PdAuthMenu> wrapper = new QueryWrapper<>();
            wrapper.eq("parent_id",pdAuthMenu.getId());
            List<PdAuthMenu> childList = pdAuthMenuService.list(wrapper);

            childList.forEach(midMenu->{
                QueryWrapper<PdAuthMenu> wrapper1 = new QueryWrapper<>();
                wrapper1.eq("parent_id", midMenu.getId());
                List<PdAuthMenu> child = pdAuthMenuService.list(wrapper1);
                midMenu.setChildren(child);

            });

            pdAuthMenu.setChildren(childList);
        });
        return list;
    }
}
